import { BaseEntity } from '@cool-midway/core';
import { Column, Entity, Index } from 'typeorm';
import { GoodsSpecEntity } from './spec';

/**
 * 文章信息
 */
@Entity('goods_info')
export class GoodsInfoEntity extends BaseEntity {
  @Index()
  @Column({ comment: '类型ID' })
  typeId: number;

  @Index()
  @Column({ comment: '资源类型ID', nullable: true })
  classId: number;

  @Index()
  @Column({ comment: '标题' })
  title: string;

  @Column({ comment: '副标题', type: 'text', nullable: true })
  subTitle: string;

  @Column({ comment: '作者', nullable: true })
  author: string;

  @Column({ comment: '发布日期', nullable: true })
  publishDate: string;

  @Column({ comment: '阅读数', default: 0 })
  readNum: number;

  @Column({ comment: '附件1', type: 'json', nullable: true })
  file1: string[];

  @Column({ comment: '附件1名称', nullable: true })
  file1Name: string;

  @Column({ comment: '附件2', type: 'json', nullable: true })
  file2: string[];

  @Column({ comment: '附件2名称', nullable: true })
  file2Name: string;

  @Column({ comment: '类型', nullable: true, default: 0 })
  tp: number;

  @Column({ comment: '资源类型', nullable: true, default: 0 })
  ztype: number;

  @Column({ comment: '主图', nullable: true })
  mainPic: string;

  @Column({ comment: '年', nullable: true })
  year: string;

  @Column({ comment: '月', nullable: true })
  month: string;

  @Column({ comment: '图片', type: 'json', nullable: true })
  pics: string[];

  @Column({
    comment: '价格',
    type: 'decimal',
    precision: 12,
    nullable: true,
    scale: 2,
  })
  price: number;

  @Column({ comment: '已售', default: 0 })
  sold: number;

  @Column({ comment: '详情', type: 'text', nullable: true })
  content: string;

  @Index()
  @Column({ comment: '状态 0-下架 1-上架', default: 0 })
  status: number;

  @Column({ comment: '排序', default: 0, nullable: true })
  sortNum: number;

  // 规格，非表字段
  specs: GoodsSpecEntity[];
}
